<meta title="免单活动管理" />
<div class="p">
    <div class="clearfix m-b-xs">
        <form class="form-inline m-b-xs pull-left" id="form">
            <select class="form-control input-sm" s="select"
                    name="status"
                    s-build="S.get('/api/enum/valuesMap/core.enums.FreeChargeActivityStatus?igNames=DELETED')">
                <option value="" selected>选择状态</option>
            </select>
            <input autocomplete="off" type="hidden" name="page" id="page" value="1"/>
            <input type="button" class="btn btn-primary btn-sm" value="查询" s-click="$page.node.val(1);$freeChargeActivitysGrid.refresh()"/>
        </form>
        <div class="text-right">
            <a href="javascript:;" class="btn btn-default btn-sm"
               s-click="add()">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a href="javascript:;" class="btn btn-default btn-sm s-loading-icon "
               s-click="return $freeChargeActivitysGrid.refresh()">
                <i class="fa fa-refresh s-loading-spinner"></i>
            </a>
        </div>
    </div>
    <div id="freeChargeActivitysGrid"
         s='datac,nda'
         s-data="search()">
        <table class="table table-striped table-bordered table-middle table-hover">
            <tr>
                <th>ID</th>
                <th>名称</th>
                <th>按钮文字</th>
                <th>打标</th>
                <th>确认描述</th>
                <th>人群</th>
                <th>物料</th>
                <th>描述</th>
                <th>频次/次数</th>
                <th class="text-right">已发放数量</th>
                <th class="text-right">最后发放时间</th>
                <th class="text-right">活动时间</th>
                <th class="text-right">创建时间</th>
                <th class="text-right">更新时间</th>
                <th>状态</th>
                <th class="text-right">操作</th>
            </tr>
            <tbody s="loop" s-data-filter="'results'">
            <tr s-loop-role="empty">
                <td colspan="16">暂无数据</td>
            </tr>
            <tr s-loop-role="row" s="datac" class="freeChargeActivity">
                <td name="id"></td>
                <td name="name"></td>
                <td name="btnTitle"></td>
                <td s="tpl">
                    <img src="{%=this.markIconUrl%}" class="adv-img" style="max-width: 100px; max-height: 50px;" />
                </td>
                <td name="confirmDescription"></td>
                <td name="crowdName"></td>
                <td name="materialName"></td>
                <td name="description"></td>
                <td>
                    <label name="freqTitle" class="label label-warning"></label>
                    <label name="maxUserDrawNum" class="label label-info"></label>
                </td>
                <td class="text-right" name="drawNum"></td>
                <td class="text-right" name="lastDrawTime"></td>
                <td class="text-right">
                    <span class="text-right" name="startTime"></span>
                    <div>
                        - <span class="text-right" name="endTime"></span>
                    </div>
                </td>
                <td class="text-right" name="createTime"></td>
                <td class="text-right" name="updateTime"></td>
                <td s="tpl">
                    {%if(this.status=='VALID'){%}
                    <label class="label label-success">{%=this.statusTitle%}</label>
                    {%}else{%}
                    <label class="label label-default">{%=this.statusTitle%}</label>
                    {%}%}
                </td>
                <td class="text-right" s="tpl">
                    {%if(this.status === 'VALID'){%}
                    <input autocomplete="off" type="button" class="btn btn-xs btn-default" value="锁定" s-click="setStatus(this, 'INVALID')"/>
                    {%}else{%}
                    <input autocomplete="off" type="button" class="btn btn-xs btn-success" value="激活" s-click="setStatus(this, 'VALID')"/>
                    {%}%}
                    <input autocomplete="off" type="button" class="btn btn-xs btn-default" value="编辑" s-click="edit(this)"/>
                    <input autocomplete="off" type="button" class="btn btn-xs btn-danger" value="删除" s-click="setStatus(this, 'DELETED')"/>
                </td>
            </tr>
            </tbody>
            <tfoot>
            <tr>
                <td colspan="16" class="text-right">
                    共有<span name="total"></span>个数据
                    <ul s="pagination"
                        s-pagination="{action:function(){$page.node.val(this); $freeChargeActivitysGrid.refresh()}}"
                        class="pagination pagination-sm">
                    </ul>
                </td>
            </tr>
            </tfoot>
        </table>
    </div>
</div>
<script type="text/javascript">

    function add() {
        S.popupOpen("/freeChargeActivity/freeChargeActivity-add.html").done(function(rs) {
            rs && $freeChargeActivitysGrid.refresh();
        })
    }

    function setStatus($this, status) {
        var data = $this.parent().data();
        S.confirm("确定操作吗？").done(function() {
            S.put("/api/freeChargeActivity/status/" + data.id + "/" + status).done(function() {
                $freeChargeActivitysGrid.refresh();
            })
        })
    }

    function search() {
        return S.get('/api/freeChargeActivity/search', $form.node.serialize()).done(function(rs) {
            if(rs.total == 0) {

            }
        })
    }

    function edit($this) {
        var data = $this.parent().data();
        S.popupOpen("/freeChargeActivity/freeChargeActivity-add.html", {freeChargeActivity: data}).done(function(rs) {
            rs && $freeChargeActivitysGrid.refresh();
        })
    }

</script>